// ---------------------------------------------------
// 按钮权限
// ---------------------------------------------------
import hasPermission from '@/utils/hasPermission'

const permission = {
  bind: (el, binding) => {
    const has = hasPermission(binding.value)

    // 无权限则移除按钮节点
    if (!has) {
      el.style.display = 'none'
      setTimeout(() => {
        el.parentNode.removeChild(el)
      }, 100)
    }
  }
}

export const setupPermissionDirective = (app) => {
  app.directive('permission', permission)
}
